package com.arithmetic;

import java.util.ArrayList;
import java.util.List;

public class D {
	public static List<String> al=new ArrayList<String>();
	public static String[] doit(char[] ch,int in){
		if(in==1){
			for(int i=0;i<ch.length;i++){
				al.add(String.valueOf(ch[i]));
			}
		}else{

			for(int i=0;i<ch.length;i++){
				doits(String.valueOf(ch[i]),ch,in-1);
			}
		}

		System.out.println("====end============");

		System.out.println("====end============"+al);
		return (String[])al.toArray(new String[al.size()]);
	}
	public static void doits(String ss,char[] ch,int in){
		if(in==1){
			for(int i=0;i<ch.length;i++){String my=ss;
					my+=ch[i];
					if(checkstr(my)){
						System.out.println(my);

						al.add(my);
					}
			}
			return ;
			
		}else{
			in--;
			for(int i=0;i<ch.length;i++){String my=ss;
					my+=ch[i];
					//System.out.println("----"+in);
					//System.out.println(aa);
					doits(my,ch,in);
			}	
		}
		return ;
	}
	public static boolean checkstr(String str){
		char[] c=str.toCharArray();
		boolean b=true;
		for(int i=0;i<c.length;i++){
			for(int j= i + 1;j<c.length;j++){
				 if(c[i] == c[j]){ 
					return false;
				 }
			}
		}
		return b;
	}

	
	public static void main(String[] args) {
		
		doit(new String("123456").toCharArray(), 6);
	}
}
